
# 脚本库：

import requests

class TestsHttpApi():
    def tests_get(self,url,data = {}):
        resp = requests.get(url,params=data)
        print(resp.text)

        return resp

    def tests_post(self,url,data = {}):
        resp = requests.post(url,data=data)
        print(resp.text)

        return resp

    def tests_put(self,url,data = {}):
        pass

    def tests_delete(self,url,data = {}):
        pass




if __name__ == '__main__':
    tests = TestsHttpApi()
    email = input("请输入邮箱：")
    pwd = input("请输入密码：")
    tests.tests_get('http://127.0.0.1:5000/user/regi/',data={'email':email,'password':pwd})
#
# #     注册
#     email = input("请输入邮箱：")
#     password = input("请输入密码：")
#     img_code = input("请输入图片验证码：")
#     code = input("请输入邮件验证码：")
#     tests.tests_post('http://127.0.0.1:5000/user/regi/', data={'email': email,'password':password,
#                                                                'img_code':img_code,'code':code})






# from utils import ImageCode,Ai,send_ran_code,SendEmail,redis_db_code
# from database import r
# from flask import make_response,request
# from manage import app
# import io
# from flask import jsonify
# # 全自动注册脚本：
# class TestsRegiApi():
#
#     def tests_get(self,url,data = {}):
#         respl = requests.get(url, params=data)
#
#         with app.app_context():
#             image = ImageCode().send_img()
#                 #         存入到内存，使用字节流的方式不占内存：
#             nei = io.BytesIO()
#             #         存入内存：
#             image[0].save(nei, 'png')
#             #         获取出数据：
#             resp = make_response(nei.getvalue())
#             # flask必要要求：
#             resp.headers['Content-Type'] = 'image/png'
#             #         将输入以邮箱的键存入到内存中：
#             r.setex(email + '_img', 300, image[1])
#
#             # 将生成的图片验证码添加到服务器中，留做识别：
#             with open('code.png','wb')as f:
#                 image[0].save(f)
#                 f.close()
#
#         return respl.text
#
#     # 发送邮箱验证码：
#     def tests_send_email(self,url,data = {}):
#         resp = requests.get(url,params = data)
#
#
#         code = send_ran_code()
#         SendEmail().send_email(email,'来自社交平台',code)
#         # 存入redis里：
#         redis_db_code(email,code)
#         print(code)
#
#         #     使用Ai技术来识别图片验证码是否正确：
#         ai = Ai()
#         token = ai.get_token()
#         respl = ai.get_img(token)
#
#         wok = ""
#         for i in respl:
#             for key,value in i.items():
#                 if key == "words":
#                     wok += value
#         if not ImageCode.static_img(email,wok):
#             return jsonify({
#                 'msg': '图像验证码不符合！',
#                 'code': 400
#             })
#
#         return resp.text
#
#
#     def tests_post(self,url,data = {}):
# #         成图片验证码并进行识别：
#         resp = requests.post(url,data=data)
#         print(resp)
#
#
#         return resp



# if __name__ == '__main__':
#     regi = TestsRegiApi()
#     email = input("请输入邮箱：")
    # regi.tests_get('http://127.0.0.1:5000/user/imgcodel/?email=' + email)
    # regi.tests_send_email('http://127.0.0.1:5000/user/sendcode/',data = {'email':email})

    # code = input("请输入邮箱验证码：")
    # password = input("请输入密码：")
    # regi.tests_post('http://127.0.0.1:5000/user/regi/',{'email':email,'code':code,'password':password})






















